package com.xbh.management.security;

import com.xbh.common.web.core.Result;
import com.xbh.management.utils.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * @program: management-center
 * @description: 未授权统一管理类,匿名用户访问某个接口时
 * @author: 许宝华
 * @create: 2021-10-05 15:24
 */

@Component
public class UnauthEntryPoint implements AccessDeniedHandler {


    private static Logger log = LoggerFactory.getLogger(UnauthEntryPoint.class);

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        log.info("自定义未授权统一返回类 ======》 没有权限访问");
        ResponseUtil.error(response, Result.result("403","no login",null));
    }




}
